#ifndef __MQTT_SUB_H__
#define __MQTT_SUB_H__

#include "mosquitto.h"
#include "cJSON.h"
#include <iostream>
#include <functional>
#include <memory>

class MqttSub
{

public:
    MqttSub();
    MqttSub(std::string &host, int port);
    ~MqttSub();
    void run();

private:
    void initMqtt();
    static void onConnectCallback(struct mosquitto *mosq, void *obj, int rc);
    static void onDisconnectCallback(struct mosquitto *mosq, void *obj, int rc);
    static void onSubscribeCallback(struct mosquitto *mosq, void *obj, int mid, int qos_count, const int *granted_qos);
    static void onMessageCallback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *msg);

private:
    mosquitto *mosq_;
    std::string host_ = "localhost";
    int port_ = 1883;
    int keep_alive_ = 60;
};

#endif